package com.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.entity.ResponseMessage;
import com.github.pagehelper.util.StringUtil;
import com.po.TalkAnime;
import com.po.TalkRotationChat;
import com.po.TalkVideo;
import com.service.TalkAnimeService;
import com.service.TalkRotationChatService;
import com.service.TalkVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/anime")
public class TalkAnimeVideoController {
    @Autowired
    private TalkVideoService talkVideoService;
    @Autowired
    private TalkAnimeService talkAnimeService;
    @Autowired
    private TalkRotationChatService talkRotationChatService;


    @RequestMapping("findList")
    public ResponseMessage findList(@RequestParam Integer current, @RequestParam Integer size,@RequestParam(required = false,defaultValue = "") String animeName){

        IPage<TalkAnime> page=new Page<>(current,size);
    IPage<TalkAnime> page1 =
        talkAnimeService.page(
            page, new LambdaQueryWrapper<TalkAnime>().like(StringUtil.isNotEmpty(animeName),TalkAnime::getName,animeName));

        return new ResponseMessage(ResponseMessage.SUCCESS,"成功",page1);
    }

    @RequestMapping("findAnimePlayList")
    public ResponseMessage findAnimePlayList(@RequestParam Integer current, @RequestParam Integer size,@RequestParam Integer animeId){

       IPage<TalkVideo> page=new Page<>(current,size);
        IPage<TalkVideo> page1 = talkVideoService.page(page,new LambdaQueryWrapper<TalkVideo>().eq(animeId!=null,TalkVideo::getAnimeId,animeId));

        return new ResponseMessage(ResponseMessage.SUCCESS,"成功",page1);
    }

    @RequestMapping("getAnimeDetailById")
    public ResponseMessage getAnimeDetailById(@RequestParam Integer id){
        TalkAnime one = talkAnimeService.getOne(new LambdaQueryWrapper<TalkAnime>().eq(id != null, TalkAnime::getId, id));

        return new ResponseMessage(ResponseMessage.SUCCESS,"成功",one);

    }

    //轮播图列表
   @RequestMapping("findRotationChatList")
    public ResponseMessage findRotationChatList(){

       List<TalkRotationChat> list = talkRotationChatService.list();
       return new ResponseMessage(ResponseMessage.SUCCESS,"成功",list);
   }


}
